package net.stuffrepos.bricknetcenter.util.gui.inputcomponent;

import java.awt.Component;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public interface InputComponentValueParser<ComponentType extends Component, ValueType> {

    public ValueResult<ValueType> fromComponent(ComponentType component);

    public void toComponent(ComponentType component, ValueType value);

    public void setEditable(ComponentType component, boolean editable);

    public static class ValueResult<ValueType> {

        private final boolean valid;
        private final ValueType value;

        public ValueResult(ValueType value, boolean valid) {
            this.value = value;
            this.valid = valid;
        }

        public boolean isValid() {
            return valid;
        }

        public ValueType getValue() {
            return value;
        }

        @Override
        public String toString() {
            return String.format("Value: \"%s\", Valid: %b", value, valid);
        }
    }
}
